package com.dz.Incubator.service.impl;

import com.dz.Incubator.dao.ProblemInfoDao;
import com.dz.Incubator.entity.ProblemInfoEntity;
import com.dz.Incubator.service.ProblemInfoService;
import com.dz.Incubator.config.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProblemInfoServiceImpl implements ProblemInfoService {

	private static final Logger logger = LoggerFactory.getLogger(ProblemInfoService.class);

    @Autowired
    private ProblemInfoDao problemInfoDao;

    @Override
    public ProblemInfoEntity insert(ProblemInfoEntity problemInfoEntity) {
        problemInfoDao.insert(problemInfoEntity);
        
        return problemInfoEntity;
    }

    @Override
    public ProblemInfoEntity update(ProblemInfoEntity problemInfoEntity) {
        problemInfoDao.update(problemInfoEntity);
        
        return problemInfoEntity;
    }

    @Override
    public Integer delete(Long id) {
        int ret = problemInfoDao.delete(id);
        return ret;
    }
    
    @Override
    public List<ProblemInfoEntity> find(Long[] ids) {
        List<ProblemInfoEntity> datas = problemInfoDao.find(ids);
        return datas;
    }

    @Override
    public ProblemInfoEntity get(Long id) {
        ProblemInfoEntity problemInfoEntity = problemInfoDao.get(id);
        return problemInfoEntity;
    }

    @Override
    public List<ProblemInfoEntity> findAll() {
    	List<ProblemInfoEntity> datas = problemInfoDao.findAll();
    	return datas;
    }
    
    @Override
    public Pagination findByPagination(Pagination pagination) {
    	List<ProblemInfoEntity> datas = problemInfoDao.findByPagination(pagination);
    	pagination.setList(datas);
    	return pagination;
    }
	
	@Override
    public List<ProblemInfoEntity> insertBatch(List<ProblemInfoEntity> list) {
        int ret = problemInfoDao.insertBatch(list);
        return list;
    }
    
    @Override
    public List<ProblemInfoEntity> updateBatch(List<ProblemInfoEntity> list) {
        int ret = problemInfoDao.updateBatch(list);
        return list;
    }
    
    @Override
    public List<Long> deleteBatch(Long[] ids) {
        int ret = problemInfoDao.deleteBatch(ids);
        List<ProblemInfoEntity>  datas = problemInfoDao.find(ids);
        List<Long> list = new ArrayList<Long>();
        for (ProblemInfoEntity data : datas) {
        	list.add(data.getId());
        }
        return list;
    }

    /**
     * 分页获取问题列表
      * @param pagination
     * @return
     */
    @Override
    public Pagination findByPaginationInfo(Pagination pagination) {
        List<ProblemInfoEntity> problemEntities = this.problemInfoDao.findByPaginationInfo(pagination);
        pagination.setList(problemEntities);
        return pagination;
    }

    @Override
    public Map<String, ProblemInfoEntity> findPrevAndNext(int id) {
        Map<String,ProblemInfoEntity> result = new HashMap<>();
        result.put("prev",this.problemInfoDao.findPrev(id));
        result.put("next",this.problemInfoDao.findNext(id));
        return result;
    }

}